package org.example;

import java.util.Objects;

/**
 * @author Tght
 * javadoc  ctrl+\
 * @date 2024/02/26
 */
public enum ColorEnum {

    SPADES(1,"♠"),
    HEARTS(2,"♥"),
    BLOCK(3,"♦"),
    PLUM_BLOSSOM(4,"♣");

    private Integer code;
    private String desc;

    ColorEnum(Integer code,String desc) {
        this.code = code;
        this.desc = desc;
    }

    public String getDesc() {
        return desc;
    }

    public Integer getCode() {
        return code;
    }

    /**
     * 根据花色code，获取对应的花色枚举
     * @param code
     * @return
     */
    public static ColorEnum getColorEnum(Integer code) {
        ColorEnum[] values = ColorEnum.values();
        for (int i = 0; i < values.length; i++) {
            if (Objects.equals(values[i].getCode(), code)){
                return values[i];
            }
        }
        return null;
    }
}
